	
var vue = new Vue({
  el: '#pageDiv',
  mounted(){
      this.getData();
  },
  data :{
	  
	  tableData : [],
	  loading: false,
	  currentPage : 1,
	  pagesize : 10,
	  totalSize : 10,
	  //url
	  queryUrl:COMMON_URL.URL+'material/pageList',
	  deleteUrl: COMMON_URL.URL+'material/deleteMateria',
	  searchUrl: COMMON_URL.URL+'material/toSearch',
	  updateUrl : COMMON_URL.URL+'material/update',
	  visible2: false,
	  dialogEdit:false,
	  dialogAdd:false,
	  dialogTitle:'',
	  form:{
          typeId:''
      },
      userConfigUpdate : {
    	  creatorType : '',
    	  creatorTypeDesc : '',
    	  name : '',
    	  memo : ''
			
		},
      items:[],
      datas:[{name:"首页展示",id:'2'},{name:"热销产品",id:'3'},{name:"全部产品",id:'4'}],
	  
	  pollingConfig:{
		  id:'',
		  kanbanPoition:'',
		  kanbanUrl :''
	  },
	  pollingConfigAdd:{
		  kanbanPoition:'',
		  kanbanUrl :''
	  },
	  searchpolling:{
		  name :'',
		  type :''
	  },
	  rules : {
		  name : [
			  {
				  required : true,message:'名称需要输入(2~6位)',trigger:'blur',min: 2,max:6
			  }
		  ]
	  }
  },
  methods:{
	  getData:function(){
          this.items = this.datas; 

      },
	  
	  dateFormat(row,col){
		  
		  var date = row[col.property];
		  if(date == null){
			  return '';
		  }
		  return moment(date).format('YYYY-MM-DD HH:mm:ss');
	  },
	  //查询数据
	  loadData(pageNum,pageSize){
		  $.ajax({
				url : this.queryUrl,
				dataType : 'json',
				type : 'get',
				data : {pageNum:pageNum,pageSize:pageSize},
				success : function(data){
					if(data.ok){
						var value = data.data.list;
						vue.tableData = value;
						vue.currentPage = data.data.currentPage;
						vue.totalSize = data.data.allCounts;
					}
				}
		  });
	  },
	  //根据条件查询数据
	  toSearch(){
		  var pageNum = 1;
		  var pageSize = 10;
		  $.ajax({
				url : this.searchUrl,
				dataType : 'json',
				type : 'get',
				data : {pageNum:pageNum,pageSize:pageSize,name:vue.searchpolling.name,type:vue.searchpolling.type},
				success : function(data){
					if(data.ok){
						var value = data.data.list;
						vue.tableData = value;
						vue.currentPage = data.data.currentPage;
						vue.totalSize = data.data.allCounts;
					}
				}
		  });
	  },
	  fullForm(row){
		  vue.userConfigUpdate = row;
	  },
	  choose(row){
		  for(var i = 0;i < vue.items.length;i++){
			  if(row.creatorType ==  vue.items[i].id){
				  row.creatorTypeDesc = vue.items[i].name;
			  }
			  
		  }
	  },
	  updateForm(id,row){
			this.$refs[id].validate((valid)=>{
				if(valid){
					$.ajax({
						url : vue.updateUrl,
						dataType : 'json',
						type : 'post',
						contentType : 'application/json',
						data : JSON.stringify(vue.userConfigUpdate),
						success : function(data){
							if(data.ok){
								vue.closePopper();
							}else{
								vue.$message({
									showClose:true,
									type:'warning',
									message:data.msg
								});
							}
						}
					});
				}else{
					return false;
				}
			});
		},
	  closePopper(){
			//vue.loadData(vue.currentPage,vue.pagesize);
			$('#user_controller_btn').trigger("click");
		},
	  //分页
	  handleSizeChange(val){
		this.pagesize = val;
		this.loadData(this.currentPage,this.pagesize);
	  },
	  //分页
	  handleCurrentChange(val){
		this.currentPage = val;
		this.loadData(this.currentPage,this.pagesize);
	  },
      //删除看板配置
      deleteConfig(index,row,value){
		  const h = this.$createElement;
		  this.$msgbox({
			  title : "警告",
			  message : h('p', null, [
	            h('span', null, '你将要删除 '),
	            h('i', { style: 'color: teal' }, row.name),
	            h('span', null, ' ?'),
	          ]),
	          showCancelButton: true,
	          confirmButtonText: '确定',
	          cancelButtonText: '取消',
	          beforeClose: (action, instance, done) => {
	              if (action === 'confirm') {
	                instance.confirmButtonLoading = true;
	                instance.confirmButtonText = '执行中...';
	        		$.ajax({
	        			type : 'get',
	        			dataType : 'json',
	        			data : {id : row.id},
	        			url : this.deleteUrl,
	        			success : function(data){
	        				if(data.ok){
	        					done();
	        					value.splice(index,1);
	        					setTimeout(() => {
	                				instance.confirmButtonLoading = false;
	                			}, 300);
	        					vue.$message({
	        			        	  showClose: true,
	        			              type: 'success',
	        			              message: '操作成功'
	        			          });
	        				}else{
	        					
	        					done();
	        					setTimeout(() => {
	                				instance.confirmButtonLoading = false;
	                			}, 300);
	        					vue.$message({
	        			        	  showClose: true,
	        			              type: 'warning',
	        			              message: data.msg
	        			          });
	    					}
	        			}
	        		});
	              }else{
	                done();
	              }
	          }
		  });
	  }
   }
});
	

//载入数据
vue.loadData(vue.currentPage, vue.pagesize);

